package com.asset.salesforce.model;
import java.io.Serializable;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

@XmlRootElement
@Table(name="country")
@Entity
public class Country implements Serializable{
	
  
   /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@JsonInclude(Include.NON_NULL)
	private Integer id;
	@JsonInclude(Include.NON_NULL)
	private String countryName;
	@JsonInclude(Include.NON_NULL)
	private String countryNameAr;
	@JsonInclude(Include.NON_NULL)
	private Set<City> cities;

	
	@XmlTransient
	@OneToMany(mappedBy="country" , fetch=FetchType.EAGER)
	public Set<City> getCities() {
		return cities;
	}

	public void setCities(Set<City> cities) {
		this.cities = cities;
	}

	/**
	 * @return the id
	 */
	 @Id
	 @GeneratedValue(strategy = GenerationType.AUTO)
	public Integer getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @return the countryName
	 */
	@Column(name="country_name")
	public String getCountryName() {
		return countryName;
	}

	/**
	 * @param countryName the countryName to set
	 */
	public void setCountryName(String countryName) {
		this.countryName = countryName;
	}

	/**
	 * @return the countryNameAr
	 */
	@Column(name="country_name_ar")
	public String getCountryNameAr() {
		return countryNameAr;
	}

	/**
	 * @param countryNameAr the countryNameAr to set
	 */
	public void setCountryNameAr(String countryNameAr) {
		this.countryNameAr = countryNameAr;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {

		return "{\"id\"        :\""+ id + "\",\"countryName\":\"" + countryName
				//+ "\",\" countryNameAr\":\"" + countryNameAr
				+"\""+",\"countryNameAr\"        :\""+this.countryNameAr+"\""+
						"}";
			//	+ /*"\",\" cities\":\"" + cities + */"\"}";
	}
	
	public String  toList(List<Country> elements){
		String str= new String("");
		for(Country element : elements){
			if(elements.size()-1 == elements.indexOf(element)){
				str+=element.toString()+"]}";
			}else{
				str +=element.toString()+",";
			}
		}
		return str;		
	}
}
